package Controller;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import Entity.Message;
import Service.MessageService;

/**
 * Servlet implementation class StudentMessageServlet
 */
@WebServlet("/StudentMessageServlet")
public class StudentMessageServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public StudentMessageServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		//显示所有反馈信息
		String op=request.getParameter("op");
		request.setCharacterEncoding("utf-8");
        HttpSession session = request.getSession(false);
        String uname = (String)session.getAttribute("uname");
        String uid = (String)session.getAttribute("uid");
        MessageService ser=new MessageService();
        if("add".equals(op)){
        	String message=request.getParameter("message");
        	Message m=new Message();
        	m.setSe_number(uid);m.setStatus(-1);m.setMess(message);m.setRe_number(uid);
        	ser.addMessage(m);
        }
        if(session == null){
            request.getRequestDispatcher("/WEB-INF/page/Login.jsp").forward(request,response);
        }
		
		List<Message> list=ser.findAllMessage();
		request.setAttribute("uname", uname);
		request.setAttribute("uid", uid);
		request.setAttribute("elist", list);
		request.getRequestDispatcher("/WEB-INF/page/StudentMessage.jsp").forward(request,response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
